using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDWDBAEND
    {
        public DataRow Convert2DWDBAEND(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDWDBAEND(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DWDBMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DWDBLFDNR"] = " ".PadRight(6 ); 
         dwReturn["DWDBDATEI"] = " ".PadRight(8 ); 
         dwReturn["DWDBTYP"] = " ".PadRight(1 ); 
         dwReturn["DWDBPROG"] = " ".PadRight(8 ); 
         dwReturn["DWDBPROZ"] = " ".PadRight(12 ); 
         dwReturn["DWDBSTA"] = " ".PadRight(1 ); 
         dwReturn["DWDBSTADAT"] = " ".PadRight(0 ); 
         dwReturn["DWDBVERS"] = " ".PadRight(10 ); 
         dwReturn["DWDBVERSDAT"] = " ".PadRight(0 ); 
         dwReturn["DWDBSCRIPT"] = " ".PadRight(1 ); 
         dwReturn["DWDBSEKI"] = " ".PadRight(1 ); 
         dwReturn["DWDBMELDKR"] = " ".PadRight(2 ); 
         dwReturn["DWDBMELDLFD"] = " ".PadRight(8 ); 
         dwReturn["DWDBTEXT01"] = " ".PadRight(60 ); 
         dwReturn["DWDBTEXT02"] = " ".PadRight(60 ); 
         dwReturn["DWDBTEXT03"] = " ".PadRight(60 ); 
         dwReturn["DWDBTEXT04"] = " ".PadRight(60 ); 
         dwReturn["DWDBTEXT05"] = " ".PadRight(60 ); 
         dwReturn["DWDBBENID"] = " ".PadRight(8 ); 
         dwReturn["DWDBFILLER"] = " ".PadRight(124 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDWDBAEND(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDWDBAEND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDWDBAEND(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDWDBAEND(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDWDBAEND(dwLocal, ITXDBVERSION);
            }
            UpdateDWDBAEND(dwLocal);
        }
        public void InsertDWDBAEND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DWDBAEND(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDWDBAEND(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DWDBAEND WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DWDBAEND  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DWDBAEND";
            Return = Result;
            return Return;
        }
        public void DeleteDWDBAEND(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DWDBAEND   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDWDBAEND(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DWDBAEND SET "
                    +"DWDBMANDANT= :DWDBMANDANT,"
                    +"DWDBLFDNR= :DWDBLFDNR,"
                    +"DWDBDATEI= :DWDBDATEI,"
                    +"DWDBTYP= :DWDBTYP,"
                    +"DWDBPROG= :DWDBPROG,"
                    +"DWDBPROZ= :DWDBPROZ,"
                    +"DWDBSTA= :DWDBSTA,"
                    +"DWDBSTADAT= :DWDBSTADAT,"
                    +"DWDBVERS= :DWDBVERS,"
                    +"DWDBVERSDAT= :DWDBVERSDAT,"
                    +"DWDBSCRIPT= :DWDBSCRIPT,"
                    +"DWDBSEKI= :DWDBSEKI,"
                    +"DWDBMELDKR= :DWDBMELDKR,"
                    +"DWDBMELDLFD= :DWDBMELDLFD,"
                    +"DWDBTEXT01= :DWDBTEXT01,"
                    +"DWDBTEXT02= :DWDBTEXT02,"
                    +"DWDBTEXT03= :DWDBTEXT03,"
                    +"DWDBTEXT04= :DWDBTEXT04,"
                    +"DWDBTEXT05= :DWDBTEXT05,"
                    +"DWDBBENID= :DWDBBENID,"
                    +"DWDBFILLER= :DWDBFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DWDBMANDANT", OracleType.NVarChar).Value = dwData["DWDBMANDANT"].ToString(); 
          or1.Parameters.Add("DWDBLFDNR", OracleType.NVarChar).Value = dwData["DWDBLFDNR"].ToString(); 
          or1.Parameters.Add("DWDBDATEI", OracleType.NVarChar).Value = dwData["DWDBDATEI"].ToString(); 
          or1.Parameters.Add("DWDBTYP", OracleType.NVarChar).Value = dwData["DWDBTYP"].ToString(); 
          or1.Parameters.Add("DWDBPROG", OracleType.NVarChar).Value = dwData["DWDBPROG"].ToString(); 
          or1.Parameters.Add("DWDBPROZ", OracleType.NVarChar).Value = dwData["DWDBPROZ"].ToString(); 
          or1.Parameters.Add("DWDBSTA", OracleType.NVarChar).Value = dwData["DWDBSTA"].ToString(); 
          or1.Parameters.Add("DWDBSTADAT", OracleType.NVarChar).Value = dwData["DWDBSTADAT"].ToString(); 
          or1.Parameters.Add("DWDBVERS", OracleType.NVarChar).Value = dwData["DWDBVERS"].ToString(); 
          or1.Parameters.Add("DWDBVERSDAT", OracleType.NVarChar).Value = dwData["DWDBVERSDAT"].ToString(); 
          or1.Parameters.Add("DWDBSCRIPT", OracleType.NVarChar).Value = dwData["DWDBSCRIPT"].ToString(); 
          or1.Parameters.Add("DWDBSEKI", OracleType.NVarChar).Value = dwData["DWDBSEKI"].ToString(); 
          or1.Parameters.Add("DWDBMELDKR", OracleType.NVarChar).Value = dwData["DWDBMELDKR"].ToString(); 
          or1.Parameters.Add("DWDBMELDLFD", OracleType.NVarChar).Value = dwData["DWDBMELDLFD"].ToString(); 
          or1.Parameters.Add("DWDBTEXT01", OracleType.NVarChar).Value = dwData["DWDBTEXT01"].ToString(); 
          or1.Parameters.Add("DWDBTEXT02", OracleType.NVarChar).Value = dwData["DWDBTEXT02"].ToString(); 
          or1.Parameters.Add("DWDBTEXT03", OracleType.NVarChar).Value = dwData["DWDBTEXT03"].ToString(); 
          or1.Parameters.Add("DWDBTEXT04", OracleType.NVarChar).Value = dwData["DWDBTEXT04"].ToString(); 
          or1.Parameters.Add("DWDBTEXT05", OracleType.NVarChar).Value = dwData["DWDBTEXT05"].ToString(); 
          or1.Parameters.Add("DWDBBENID", OracleType.NVarChar).Value = dwData["DWDBBENID"].ToString(); 
          or1.Parameters.Add("DWDBFILLER", OracleType.NVarChar).Value = dwData["DWDBFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
